package sps.admin.util;

import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.Date;

/**
 * TODO
 *
 * @Description
 * @Author Felix
 * @Date 2025-01-06 13:20
 **/
public class DateUtils {

    public static String TimeDifference(String startTime,String endTime){
        try {
            SimpleDateFormat format = new SimpleDateFormat("HH:mm");
            Date date1 = format.parse(startTime);
            Date date2 = format.parse(endTime);
            long diff = date2.getTime() - date1.getTime();// 计算两个时间的毫秒时间差
            long diffHours = diff / (30 * 60 * 1000); // 将差异转换为半小时
            if(startTime.compareTo("11:30") == -1 ){ //11:30到12:30算吃饭时间
                diffHours+=-2;
            }
            if (endTime.compareTo("18:00") == 1) { //17:00到18:00算吃饭时间
                diffHours+=-2;
            }
            String overtime = diffHours / 2 + (diffHours % 2 == 1 ? ".5" : "");
            if(Long.valueOf(overtime) > 10){
                return  "10";
            }
            return  overtime;
        } catch (Exception e) {
            e.printStackTrace();
            return "0";
        }
    }

    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        LocalDate saturday;
        LocalDate sunday;

        if (today.getDayOfWeek() == DayOfWeek.SATURDAY) {
            saturday = today;
            sunday = today.plusDays(1);
        } else if (today.getDayOfWeek() == DayOfWeek.SUNDAY) {
            saturday = today.minusDays(1);
            sunday = today;
        } else {
            saturday = today.with(DayOfWeek.SATURDAY);
            sunday = today.with(DayOfWeek.SUNDAY);
        }

        System.out.println("Saturday: " + saturday);
        System.out.println("Sunday: " + sunday);
    }


}
